package com.jiang.starter.redis.channel;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

/**
 * 创建Channel的工厂Bean
 */
public class ChannelFactoryBean<T> implements FactoryBean<T> {

    /**
     * 需要创建的Bean的类型
     */
    public final Class<T> type;
    public ChannelFactoryBean(Class<T> type) {
        this.type = type;
    }

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 返回代理对象
     */
    @Override
    public T getObject() {
        return (T) ChannelInvocationHandler.generateProxyClass(type, applicationContext);
    }

    @Override
    public Class<?> getObjectType() {
        return type;
    }
}
